Skip to content

[Breaking change] Load platform fonts fallback to avoid squares instead of glyphs - #49

Open
MaximeRougieux wants to merge 5 commits into
chore/lint-and-cifrom
feat/font-fallback-v2
Open

[Breaking change] Load platform fonts fallback to avoid squares instead of glyphs#49
MaximeRougieux wants to merge 5 commits into
chore/lint-and-cifrom
feat/font-fallback-v2

Conversation

@MaximeRougieux

Copy link
Copy Markdown
Contributor

With this PR, the fonts loaded by the package now also includes fallback system fonts that are not declared in the manifest, but that are sometimes used in Flutter widgets like Material and Cupertino widgets

This behavior is optional and can be opted-out (though it is on by default)

MaximeRougieux and others added 5 commits August 3, 2026 15:21
The matrix only covered the three example apps, so nothing under `test/` ever
ran on CI. Format and analyze are left out of this job for now: the package
sources still carry pre-existing analyzer infos.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A font bundled by a dependency is exposed by the font manifest as
`packages/my_theme/Roboto`, and `loadFonts()` only registered it under that
name. A widget styled with `TextStyle(fontFamily: 'Roboto', package:
'my_theme')` — or a theme defaulting to that family — asks for the bare
`Roboto` instead, so no font was found and the text rendered as placeholder
blocks in the goldens.

Register both names. `loadFonts()` now returns the families it registered,
which is also what lets the tests assert on it without shared state.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The families a widget gets when it specifies no font — `Roboto` on Android,
`CupertinoSystemText` on iOS, `Segoe UI` on Windows — are declared in no
`pubspec.yaml`: they either ship with the Flutter SDK or belong to the host OS.
`loadFonts()` could not find them in the font manifest, so a `DatePickerDialog`
or a `CupertinoButton` rendered as placeholder blocks in the goldens.

The list is gathered from `Typography` and `CupertinoTextThemeData` instead of
being hardcoded, so it follows the SDK. The families the SDK ships are loaded
from its font cache, found through `FLUTTER_ROOT` or by walking up from the
test executable. The ones only the OS can provide are aliased to the typeface
the SDK ships: the glyphs then differ from a real device, but the goldens stay
readable. Opt out with `setLoadPlatformFallbackFonts(false)`.

`FontLoadingPolicy` holds what is registered on top of the manifest, and with
it the arbitration introduced here: a dependency font does not claim the bare
name of a platform default the SDK ships a font for. It usually bundles a
single weight of such a family while the SDK ships all of them, and on a device
it would not shadow the platform font either.

The SDK font files are sorted before being registered: a directory listing
comes back in file system order, which differs between APFS, ext4 and NTFS,
and goldens must not depend on the machine that generated them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@MaximeRougieux
MaximeRougieux changed the base branch from main to chore/lint-and-ci August 3, 2026 13:57
@T-moz
T-moz self-requested a review August 3, 2026 14:11
@MaximeRougieux
MaximeRougieux force-pushed the chore/lint-and-ci branch 3 times, most recently from af61701 to 7837c46 Compare August 4, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant